//
//  AXFMineViewController.m
//  AIXF
//
//  Created by Macx on 2017/7/9.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "AXFMineViewController.h"
#import "AXFMineSever.h"
#import "AXFMineHeadView.h"
#import "AXFAddressViewController.h"
#import "AXFMyShopViewController.h"
#import "AXFSharedViewController.h"
#import <Masonry.h>

#import "AXFspecialViewController.h"

#import "AXFAccountSettingViewController.h"

#import "AXFAccountView.h"
#import "AXFMyOrderViewController.h"
#import "AXFMyMessageViewController.h"
@interface AXFMineViewController ()<UITableViewDataSource,UITableViewDelegate>


@property (nonatomic,strong)NSArray *dataArray;

@end

static NSString *tableViewCell = @"tableViewCell";

@implementation AXFMineViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];


    //self.navigationController.navigationBarHidden = YES;


//    self.navigationController.navigationBarHidden = YES;


    
    [self loadData];
    
    AXFAccountView *accountView = [AXFAccountView new];
    
    [self.view addSubview:accountView];
    
    for (UIView *subview in accountView.subviews)
    {
        if ([subview isKindOfClass:[UIButton class]])
        {
            UIButton *settingBtn = (UIButton *)subview;
            
            [settingBtn addTarget:self action:@selector(clickSetting) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    
    [accountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.offset(200);
    }];
    
    UITableView *tabelView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    
    [tabelView registerClass:[UITableViewCell class] forCellReuseIdentifier:tableViewCell];
    
    [self.view addSubview:tabelView];
    
    [tabelView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view);
        make.top.equalTo(accountView.mas_bottom);
    }];
    
    AXFMineHeadView *headView = [[AXFMineHeadView alloc] initWithFrame:CGRectMake(0, 0, 375, 60)];
    

    
    tabelView.tableHeaderView = headView;
    
    tabelView.dataSource = self;
    
    tabelView.delegate = self;
    

    for (UIView *subView in headView.subviews)
    {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapView:)];
        
        [subView addGestureRecognizer:tap];
    }

  
}

- (void)tapView:(UITapGestureRecognizer *)tap
{
    if ([tap.view.restorationIdentifier isEqualToString:@"1"])
    {
        AXFMyOrderViewController *order = [[AXFMyOrderViewController alloc]init];
        
        [self.navigationController pushViewController:order animated:YES];
        
    }else if ([tap.view.restorationIdentifier isEqualToString:@"2"])
    {
        AXFspecialViewController *special = [[AXFspecialViewController alloc]init];
        
        [self.navigationController pushViewController:special animated:YES];
        
        
        NSLog(@"我的优惠券");
    }else if ([tap.view.restorationIdentifier isEqualToString:@"3"])
    {
        NSLog(@"我的消息");
        
        AXFMyMessageViewController *vc = [AXFMyMessageViewController new];
    
        [self.navigationController pushViewController:vc animated:YES];
    }
        
}

- (void)clickSetting
{
    AXFAccountSettingViewController *vc = [AXFAccountSettingViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AXFAddressViewController *address = [[AXFAddressViewController alloc]init];
    
    //我的店铺
    AXFMyShopViewController *shop = [[AXFMyShopViewController alloc]init];
    
    AXFSharedViewController *shared = [[AXFSharedViewController alloc]init];

    if (indexPath.section == 0) {
        
        switch (indexPath.row) {
            case 0:
                [self.navigationController pushViewController:address animated:YES];
                break;
                
            case 1:
                //我的店铺
                [self.navigationController pushViewController:shop animated:YES];
                break;
        }
 
    }else if (indexPath.section == 1){
        
        [self.navigationController pushViewController:shared animated:YES];
        
    }else{
        
        //最后一组cell
        
        
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    NSInteger row = 0;
    
    switch (section) {
        case 0:
            row = 2;
            break;
        case 1:
            row = 1;
            break;
        case 2:
            row = 2;
            break;
    }
    
    return row;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewCell forIndexPath:indexPath];
    
     [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    NSArray *sectionArray = self.dataArray[indexPath.section];
    
    NSDictionary *dict = sectionArray[indexPath.row];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    cell.imageView.image = [UIImage imageNamed:dict[@"iconName"]];
    
    cell.textLabel.text = dict[@"title"];
    
    
    return cell;
}



- (void)loadData
{
    self.dataArray = @[
                       @[
                            @{@"iconName": @"v2_my_address_icon",@"title": @"我的收货地址"},
                            @{@"iconName":@"icon_mystore",@"title":@"我的店铺"}
                         ],
                       @[
                            @{@"iconName":@"v2_my_share_icon",@"title":@"把爱鲜蜂分享给朋友"}
                         ],
                       @[
                            @{@"iconName":@"online_service",@"title":@"客服帮助"},
                            @{@"iconName":@"v2_my_feedback_icon",@"title":@"意见反馈"}
                         ]
                           ];
}


@end
